#include<iostream>
using namespace std;

#include<mutex>

// 饿汉
//class SingleLeton
//{
//public:
//  SingleLeton* GetInst()
//  {
//    return &_inst;
//  }
//
//
//private:
//  static SingleLeton _inst;
//};
//
//SingleLeton SingleLeton::_inst;

// 懒汉
class SingleLeton
{

  SingleLeton()
  {}

  SingleLeton(const SingleLeton& sl) = delete;
  SingleLeton& operator=(const SingleLeton& sl) = delete;

public:
  static SingleLeton* GetInst()
  {
    if(_pinst == nullptr)
    {
      static mutex _mtx;
      unique_lock<mutex> lg(_mtx);

      if(_pinst == nullptr)
      {
        _pinst = new SingleLeton;
      }
    }

    return _pinst;
  }

private:
  static SingleLeton* _pinst;
};
SingleLeton* SingleLeton::_pinst = nullptr;

int main()
{
  SingleLeton::GetInst();

  return 0;
}
